package com.yzt.zhuju.widget;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.yzt.zhuju.R;
import com.yzt.zhuju.manager.FontManager;

/**
 * author : bob
 * date   : 2022/12/5
 * desc   :
 */
public class ShineUidView extends LinearLayout {

    private final Context mContext;

    private TextView mUIDText;

    private ImageView niceAccountLabel;

    public ShineUidView(Context context) {
        super(context);
        mContext = context;
        init(context, null);
        initView();
    }

    public ShineUidView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        init(context, attrs);
        initView();
    }

    public ShineUidView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        init(context, attrs);
        initView();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public ShineUidView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mContext = context;
        init(context, attrs);
        initView();
    }

    public void init(Context context, AttributeSet attrs) {
    }

    private void initView() {
        View mView = LayoutInflater.from(mContext).inflate(R.layout.layout_shine_uid, this, true);
        mUIDText = mView.findViewById(R.id.personal_info_uid);
        niceAccountLabel = mView.findViewById(R.id.iv_nice_account_label);
    }

    public void setUserId(String userId, long shineUserId, boolean isNobleShineId) {
        if (shineUserId > 0) {
            mUIDText.setText(String.valueOf(shineUserId));
            niceAccountLabel.setVisibility(View.VISIBLE);
            if (FontManager.getInstance().getTypeface() != null) {
                mUIDText.setTypeface(FontManager.getInstance().getTypeface());
            }
            niceAccountLabel.setVisibility(View.VISIBLE);
            if (isNobleShineId) {
                //贵族
                niceAccountLabel.setImageResource(R.mipmap.icon_liang_guizu);
                mUIDText.setTextColor(Color.parseColor("#FFAE00"));
            } else {
                niceAccountLabel.setImageResource(R.mipmap.nice_account_label);
                mUIDText.setTextColor(Color.parseColor("#FF00FF"));
            }
        } else {
            mUIDText.setVisibility(VISIBLE);
            mUIDText.setText(userId);
            niceAccountLabel.setVisibility(View.GONE);
            mUIDText.setTextColor(getResources().getColor(R.color.color_6D7278));
        }
    }
}

